/**
****************************(C) COPYRIGHT 2025 ROBOT-Z****************************
  * @file       shoot.c/h
  * @brief      2025赛季哨兵射击功能
  * @note
  * @history
  *  Version    Date            Author          Modification
  *  V1.0.0     Dec-26-2018     RM              1. 完成
  *  v2.0.0		Dec-20-2024		冉文治			1. 修改了发射逻辑
  *								卢俊烨			2. 对卡弹进行处理
  *								吴森桦
  *
  @verbatim
  ==============================================================================

  ==============================================================================
  @endverbatim
  ****************************(C) COPYRIGHT 2025 ROBOT-Z****************************
  */

#ifndef SHOOT_H
#define SHOOT_H

#include "main.h"
#include "CAN_receive.h"
#include "remote_control.h"
#include "user_lib.h"
#include "pid.h"

// 射击发射开关通道数据
#define SHOOT_RC_MODE_CHANNEL				1
// 摩擦轮最大与最小速度
#define SHOOT_FRIC_MAX_SPEED    			6000.0f
#define SHOOT_FRIC_MIN_SPEED				0.0f
// 拨弹频率PID
#define TRIGGER_COOLING_HEAT_PID_KP			100.0f
#define TRIGGER_COOLING_HEAT_PID_KI			0.0f
#define TRIGGER_COOLING_HEAT_PID_KD			50.0f
#define TRIGGER_COOLING_HEAT_PID_MAX_OUT	3000.0f
#define TRIGGER_COOLING_HEAT_PID_MAX_IOUT	0.0f

// 拨弹电机PID
#define TRIGGER_SPEED_PID_KP				1000.0f
#define TRIGGER_SPEED_PID_KI				0.0f
#define TRIGGER_SPEED_PID_KD				200.0f
#define TRIGGER_READY_PID_MAX_OUT			10000.0f
#define TRIGGER_READY_PID_MAX_IOUT			0.0f
// 摩擦轮PID
#define FRIC_SPEED_PID_KP					20.0f
#define FRIC_SPEED_PID_KI					0.0f
#define FRIC_SPEED_PID_KD					50.0f
#define FRIC_BULLET_PID_MAX_OUT				16000.0f
#define FRIC_BULLET_PID_MAX_IOUT			0.0f

// 斜波函数斜率
#define FRIC_START							10.0f
#define FRIC_CLOSE							-10.0f

typedef enum
{
    SHOOT_STOP = 0,
    SHOOT_READY,
	SHOOT_START
} shoot_mode_e;

typedef struct
{
	const motor_measure_t *fric_motor_measure;
	first_order_filter_type_t fric_filter;
	int16_t fric_speed;
	int16_t fric_speed_set;
	int16_t fric_given_current;
} fric_motor_t;

typedef struct
{
	const motor_measure_t *trigger_motor_measure;
	int16_t trigger_speed;
	int16_t trigger_speed_set;
	int16_t trigger_given_current;
} trigger_motor_t;

typedef struct
{
	const RC_ctrl_t *shoot_rc;

	fric_motor_t fric_motor[2];
	trigger_motor_t trigger_motor;
    shoot_mode_e shoot_mode;
	shoot_mode_e shoot_last_mode;
    ramp_function_source_t fric_ramp;

	pid_type_def trigger_motor_pid_cooling_heat;
	pid_type_def trigger_motor_pid_speed;
    pid_type_def fric1_motor_pid_speed;
    pid_type_def fric2_motor_pid_speed;

	fp32 blocking_start_flag;
	fp32 blocking_over_flag;

} shoot_control_t;

/**
  * @brief          射击初始化，初始化PID，遥控器指针，电机指针
  * @author			冉文治
  * @param			void
  * @retval         返回空
  */
extern void shoot_init(void);

/**
  * @brief          射击循环
  * @author			冉文治
  * @param			void
  * @retval         无
  */
extern void shoot_control_loop(void);

extern const shoot_control_t *get_shoot_motor_point(void);

#endif
